package org.hong.monkey.rpc

import java.net.URI

import org.hong.monkey.util.Utils

/**
 */
private[monkey] case class RpcAddress(host:String, port:Int) {

  def hostPort: String = host + ":" + port

  def toMonkeyURL: String = "monkey://" + hostPort

  override def toString: String = hostPort
}

private[monkey] object RpcAddress {
  def fromURIString(uri: String): RpcAddress = {
    val urlObj = new URI(uri)
    RpcAddress(urlObj.getHost, urlObj.getPort)
  }

  def fromMonkeyURL(monkeyUrl: String): RpcAddress = {
    val (host, port) = Utils.extractHostPortFromMonkeyUrl(monkeyUrl)
    RpcAddress(host, port)
  }
}
